package com.tf_cut.admin.datadic.controller;

import com.alibaba.fastjson.JSON;
import com.tf_cut.admin.backend.api.BackEndApi;
import com.tf_cut.admin.common.pojo.Result;
import com.tf_cut.admin.datadic.vo.DatadicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/backend")
public class DatadicController {

    @Autowired
    private BackEndApi agentApi;

    @GetMapping("/dict/notice")
    public ModelAndView notice() {
        return new ModelAndView("sys/setting/notice", "notice", null);
    }

    @GetMapping("/dict/getShowTime")
    public String getShowTime(){
        return agentApi.getShowTime();
    }

    @GetMapping("/dict/getDict")
    public Result<List<DatadicVo>> getDict(@RequestParam String code){
        String json = agentApi.getdataDicVoWithCode(code);
        List<DatadicVo> list = JSON.parseArray(json,DatadicVo.class);
        return Result.of(list);
    }

    @PostMapping("/dict/modifyNoticeEmail")
    public Result modifyNoticeEmail(DatadicVo datadicVo){
        return Result.of(agentApi.updDatadic(JSON.toJSONString(datadicVo)));
    }

    @GetMapping("/dict/sendMain")
    public String sendMail(String flag,String name,String money,StringBuffer time){
    	time.insert(10, " ");
        return agentApi.sendMail(flag,name,money,new String(time));
    }
}
